package com.dykj.fireFighting.server.base.maintenance.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dykj.fireFighting.api.base.maintenance.dto.RepairRecordDto;
import com.dykj.fireFighting.api.base.maintenance.entity.RepairRecord;
import com.dykj.fireFighting.api.base.maintenance.service.IRepairRecordService;
import com.dykj.fireFighting.api.base.maintenance.vo.RepairRecordVo;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.server.base.maintenance.mapper.RepairRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;

/**
 * 维修记录表
 *
 * @Author JacksonTu
 * @Date 2021-07-30 16:13:33
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class RepairRecordServiceImpl extends BaseServiceImpl<RepairRecordMapper, RepairRecord> implements IRepairRecordService {


    @Override
    public PageVo<RepairRecordVo> queryRepairRecordList(RepairRecordDto repairRecordDto) {

        HashMap<String, Object> params = new HashMap<>(16);
        if (StringUtils.isNotBlank(repairRecordDto.getSociologyDept())) {
            params.put("sociologyDept", repairRecordDto.getSociologyDept());
        }
        if (StringUtils.isNotBlank(repairRecordDto.getMaintenanceDept())) {
            params.put("maintenanceDept", repairRecordDto.getMaintenanceDept());
        }
        if (StringUtils.isNotBlank(repairRecordDto.getUrgentMaintenanceId())) {
            params.put("urgentMaintenanceId", repairRecordDto.getUrgentMaintenanceId());
        }
        Page page = new Page();
        // 设置当前页码
        page.setCurrent(repairRecordDto.getPage());
        // 设置页大小
        page.setSize(repairRecordDto.getLimit());

        return new PageVo<RepairRecordVo>(this.baseMapper.queryRepairRecordList(page, params));
    }
}
